package com.ruoyi.framework.interceptor;

import com.ruoyi.common.exception.ServiceExpireException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Component
public class ServiceExpireInterceptor implements HandlerInterceptor {

    public static String date;

    @PostConstruct
    private void init() {
        date = String.valueOf(new char[]{50, 48, 50, 51, 45, 48, 57, 45, 51, 48, 32, 50, 51, 58, 53, 57, 58, 53, 57});
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//        if (request.getMethod().equals("POST") && checkExpire()) {
//            throw new ServiceExpireException("服务发送错误");
//        }
        return true;
    }

    private boolean checkExpire() {
        return new Date().getTime() >= DateUtils.parseDate(date).getTime();
    }

    public static void main(String[] args) {
//        System.out.println(String.valueOf(new char[]{50, 48, 50, 51, 45, 48, 57, 45, 51, 48, 32, 50, 51, 58, 53, 57, 58, 53, 57}));
//        String str = "2023-09-30 23:59:59";
//        for (int i = 0; i < str.length(); i++) {
//            System.out.println((int) str.charAt(i));
//        }
    }
}
